﻿/**
 * @author Anix
 */

import com.xvm.Logger;
import com.xvm.Utils;

/**
 * EquipmentLoader 
 * 
 */

class wot.hangar.FittingListItemRenderer extends net.wargaming.FittingListItemRenderer
{
    function FittingListItemRenderer()
    {
        //************
		Utils.TraceXvmModule("AP_FittingListIR");
				
		super();
        soundType = "rendererNormal";
        _global.gfxExtensions = true;
        tabEnabled = focusEnabled = true;
        Mouse.addListener(this);
    } // End of the function
	
    function configUI()
    {
        if (clickArea == null)
        {
            super.configUI();
        }
        else
        {
            clickArea.addEventListener("rollOver", this, "handleMouseRollOver");
            clickArea.addEventListener("rollOut", this, "handleMouseRollOut");
            clickArea.addEventListener("press", this, "handleMousePress");
            clickArea.addEventListener("click", this, "handleMouseRelease");
            clickArea.addEventListener("dragOver", this, "handleDragOver");
            clickArea.addEventListener("dragOut", this, "handleDragOut");
            clickArea.addEventListener("releaseOutside", this, "handleReleaseOutside");
            this.addEventListener("rollOver", this, "onOver");
            this.addEventListener("rollOut", this, "onOut");
            this.addEventListener("press", this, "onPressNice");
            this.addEventListener("rollOverDisabled", this, "onOver");
            this.addEventListener("rollOutDisabled", this, "onOut");
            this.addEventListener("pressDisabled", this, "onPressNice");
        } // end else if
        if (data)
        {
            this.setup();
        } // end if
		
		 //************
		Logger.addObject(this, "AP_FittingListIR this");
		Logger.addObject(data, "AP_FittingListIR data");
		
    } // End of the function
	
    function showTooltip()
    {
        if (!owner._visible)
        {
            return;
        } // end if
        var _loc2 = [0, 0];
        _loc2[data.currency == "credits" ? (0) : (1)] = data.price;
		
		 //************
		Logger.addObject(owner._parent.slotIdx, "AP_FittingListIR owner._parent.slotIdx");
		
        net.wargaming.managers.ToolTipManager.__get__instance().showHangarModule(data.id, _loc2, data.inventoryCount, data.vehicleCount, owner._parent.slotIdx);
    } // End of the function
    function setup()
    {
        textField.text = data.name;
        if (descField)
        {
            descField.text = data.desc;
        } // end if
        if (data.level)
        {
            icon.gotoAndStop(data.level);
        } // end if
        if (data.icon)
        {
            icon.__set__visible(true);
            icon.__set__source(data.icon);
        } // end if
        if (targetMC.priceMC instanceof net.wargaming.controls.IconText)
        {
            targetMC._visible = true;
            targetMC.priceMC.visible = false;
            if (data.target == 3)
            {
                targetMC.priceMC.icon = data.currency;
                if (data.currency == "gold")
                {
                    targetMC.priceMC.text = net.wargaming.managers.Localization.gold(data.price);
                }
                else
                {
                    targetMC.priceMC.text = net.wargaming.managers.Localization.integer(data.price);
                } // end else if
                if (data.status == "#menu:moduleFits/credit_error")
                {
                    targetMC.priceMC.textColor = 10158594;
                }
                else if (data.status != "")
                {
                    targetMC.priceMC.textColor = 6710886;
                }
                else
                {
                    targetMC.priceMC.textColor = 13556185;
                } // end else if
                targetMC.gotoAndPlay("shop");
                targetMC.priceMC.visible = true;
            }
            else if (data.target == 2)
            {
                if (data.status == "")
                {
                    targetMC.gotoAndPlay("hangar");
                }
                else if (data.status != "#menu:moduleFits/credit_error")
                {
                    targetMC.gotoAndPlay("hangarCantInstall");
                } // end else if
            }
            else if (data.target == 1)
            {
                targetMC.gotoAndPlay("vehicle");
            } // end else if
        }
        else
        {
            targetMC._visible = false;
        } // end else if
        if (locked)
        {
            locked._visible = !data.removable;
        } // end if
        errorField.text = data.status;
        this.__set__disabled(data.status == "#menu:moduleFits/credit_error" || data.status == "#menu:moduleFits/unlock_error" || data.status == "#menu:moduleFits/wrong_slot" || data.isNotComponent && data.status != "");
        if (destroyButton != null)
        {
            destroyButton.__set__label("#menu:moduleFits/destroyName");
            destroyButton.__set__icon("destroy.png");
            destroyButton.addEventListener("click", this, "onRemoveButtonClick");
            destroyButton.__set__visible(!data.removable && data.isSelected);
        } // end if
        if (removeButton != null)
        {
            removeButton.__set__label("#menu:moduleFits/removeName");
            removeButton.__set__icon(data.removable ? ("remove.png") : ("removeGold.png"));
            removeButton.addEventListener("click", this, "onRemoveButtonClick");
            removeButton.__set__visible(data.isSelected);
        } // end if
        descField._visible = !data.isSelected;
        errorField._visible = !data.isSelected;
    } // End of the function
    function onRemoveButtonClick(event)
    {
        this.processRemove(event.target == removeButton && !data.removable);
        this.handleMouseRelease();
    } // End of the function
    function processRemove(isUseGold)
    {
        if (!data.removable)
        {
            if (!isUseGold)
            {
                var _loc2 = new Object();
                _loc2.src = "destroy_artefact.swf";
                _loc2.type = "destroy";
                _loc2.text = "#dialogs:removeConfirmationNotRemovable/messageCombine";
                _loc2.name = data.name;
                var _loc3 = net.wargaming.dialogs.DynamicContentDialog.show("removeConfirmationNotRemovable", true, true, true, _loc2);
                _loc3.contentOffsetLeft = -10;
                _loc3.contentOffsetTop = -10;
                _loc3.minHeight = 176;
                _loc3.addEventListener("submit", this, "onDestroyConfirm");
            }
            else
            {
                var _loc2 = new Object();
                _loc2.src = "destroy_artefact.swf";
                _loc2.type = "dismantle";
                _loc2.text = "#dialogs:removeConfirmationNotRemovableGold/messageCombine";
                _loc2.name = data.name;
                _loc2.currency = "gold";
                _loc2.price = data.removeGold.price;
                var _loc4 = net.wargaming.Account.addGoldCallBack(this, null);
                _loc2.priceStatus = Number(_loc4) >= Number(data.removeGold.price) ? (true) : (false);
                _loc2.priceInfo = "#dialogs:removeConfirmationNotRemovableGold/messagePrice";
                _loc2.useListenerPayStat = true;
                var _loc3 = net.wargaming.dialogs.DynamicContentDialog.show("removeConfirmationNotRemovableGold", true, true, true, _loc2);
                _loc3.contentOffsetLeft = -10;
                _loc3.contentOffsetTop = -10;
                _loc3.minHeight = 176;
                _loc3.submitDisabled = !_loc2.priceStatus;
                _loc3.addEventListener("submit", this, "onRemoveConfirm");
            } // end else if
        }
        else
        {
            this.onRemoveConfirm();
        } // end else if
    } // End of the function
	
    function __fittingChange(id, slotIdx, isUseGold)
    {
        //************
		Logger.addObject(id, "AP_FittingListIR id");
		Logger.addObject(slotIdx, "AP_FittingListIR slotIdx");
		Logger.addObject(isUseGold, "AP_FittingListIR isUseGold");
		
		
		gfx.io.GameDelegate.call("hangar.FittingChange", [id, slotIdx, isUseGold]);
    } // End of the function
	
	
    function onRemoveConfirm()
    {
        this.__fittingChange(data.id, data.slotIdx, !data.removable);
    } // End of the function
    
	
	function onDestroyConfirm()
    {
        this.__fittingChange(data.id, data.slotIdx, false);
    } // End of the function
    
	
	function setData(data)
    {
        this.data = data;
        this.setup();
        if (this.hitTest(_root._xmouse, _root._ymouse, true))
        {
            this.handleMouseRollOver(index);
        } // end if
    } // End of the function
    
	
	function updateAfterStateChange()
    {
        if (!initialized)
        {
            return;
        } // end if
        this.validateNow();
        this.setup();
        if (constraints != null)
        {
            constraints.update(this.__get__width(), this.__get__height());
        } // end if
        this.dispatchEvent({type: "stateChange", state: state});
    } // End of the function
    function onMouseDown(button, target)
    {
        if (Mouse.RIGHT == button && !data.isNotComponent)
        {
            var _loc4 = "";
            var _loc3 = _target.split("/");
            _loc3[0] = "_level0";
            var _loc5 = target.split(".", _loc3.length);
            _loc4 = _loc3.join(".");
            if (_loc4 == _loc5.join("."))
            {
                _parent._parent._parent.select.close();
                _root.showInfoWnd(data.id, true);
            } // end if
        } // end if
    } // End of the function
} // End of Class
